<?php
declare(strict_types=1);
/*
销售退货单
*/
namespace Modules\Salesmanagement\Http\Controllers;

use Catch\Base\CatchController as Controller;
use Modules\Salesmanagement\Models\Salesreturn;
use Illuminate\Http\Request;
use extend\services\warehouse\{warehouseService};//引入自定义类
use Modules\Salesmanagement\Http\Repositories\SalesreturnRequest;

class SalesreturnController extends Controller
{
    public function __construct(
        protected readonly Salesreturn $model
    ){}

    /**
     * @param Request $request
     * @return mixed
     */
    public function index(): mixed
    {
       $data = $this->model->getList();
       $kingDeeService = new warehouseService();
       $datauser = $kingDeeService->uerdata();
        foreach($data as $k=>$v){
            if ($v['writestate']==1) {
                $data[$k]['writestate'] = '回写成功';
            }else{
                $data[$k]['writestate'] = '';
            }
            $data[$k]['creator_id'] = isset($datauser[$v['creator_id']])?$datauser[$v['creator_id']]['username']:'';
            switch ($v['state']){
                case 0:
                    $data[$k]['description'] = '待审核'; 
                break;
                
                case 1:
                    $data[$k]['description'] = '已审核'; 
                break;
            }

        }
        return $data;
        
    }

    /**
     * @param Request $request
     * @return mixed
     */
    public function store(Request $request)
    {
        $data = $request->all();
        $data['creator_id'] =$this->getLoginUserId();//当前登录用户名称
        return SalesreturnRequest::create($data);
        //return $this->model->storeBy($request->all());
    }

    /**详情接口
     * @param $id
     * @return mixed
     */
    public function show($id,Request $request)
    {
    
        return SalesreturnRequest::DetailinterfaceData($id,$request->all());
        // return $this->model->firstBy($id);
    }

    /**
     * @param Request $request
     * @param $id
     * @return mixed
     */
    public function update($id, Request $request)
    {
        return $this->model->updateBy($id, $request->all());
    }

    /**
     * @param $id
     * @return mixed
     */
    public function destroy($id)
    {
        return SalesreturnRequest::delete($id);
    }


    
    /**条码扫描接口
     * @param $id
     * @return mixed
     */
    public function barcode($code)
    {
        return SalesreturnRequest::codedata($code);
    }


     
    /**审核接口推送到金蝶
     * @param $id
     * @return mixed
     */
    public function interfaceApi($id)
    {
        return SalesreturnRequest::pdassanningaddData($id);
    }


     /**PDA 组织间扫描接口-》审核接口推送到金蝶
     * @param $id
     * @return mixed
     */
    public function codetissue($code)
    {
        return SalesreturnRequest::codetissueData($code);
    }

    /**PDA 组织间扫描接口-》审核接口推送到金蝶
     * @param $id
     * @return mixed
     */
    public function submitdata(Request $request)
    {
        return SalesreturnRequest::submitdataAdd($request->all());
    }

}
